package com.ruoyi.qt.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.qt.domain.QtMistake;
import com.ruoyi.qt.service.IQtMistakeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 错题Controller
 * 
 * @author ruoyi
 * @date 2021-12-06
 */
@RestController
@RequestMapping("/qt/mistake")
public class QtMistakeController extends BaseController
{
    @Autowired
    private IQtMistakeService qtMistakeService;

    /**
     * 查询错题列表
     */
    @PreAuthorize("@ss.hasPermi('qt:mistake:list')")
    @GetMapping("/list")
    public TableDataInfo list(QtMistake qtMistake)
    {
        startPage();
        List<QtMistake> list = qtMistakeService.selectQtMistakeList(qtMistake);
        return getDataTable(list);
    }

    /**
     * 导出错题列表
     */
    @PreAuthorize("@ss.hasPermi('qt:mistake:export')")
    @Log(title = "错题", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(QtMistake qtMistake)
    {
        List<QtMistake> list = qtMistakeService.selectQtMistakeList(qtMistake);
        ExcelUtil<QtMistake> util = new ExcelUtil<QtMistake>(QtMistake.class);
        return util.exportExcel(list, "错题数据");
    }

    /**
     * 获取错题详细信息
     */
    @PreAuthorize("@ss.hasPermi('qt:mistake:query')")
    @GetMapping(value = "/{mistakeId}")
    public AjaxResult getInfo(@PathVariable("mistakeId") String mistakeId)
    {
        return AjaxResult.success(qtMistakeService.selectQtMistakeByMistakeId(mistakeId));
    }

    /**
     * 新增错题
     */
    @PreAuthorize("@ss.hasPermi('qt:mistake:add')")
    @Log(title = "错题", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody QtMistake qtMistake)
    {
        return toAjax(qtMistakeService.insertQtMistake(qtMistake));
    }

    /**
     * 修改错题
     */
    @PreAuthorize("@ss.hasPermi('qt:mistake:edit')")
    @Log(title = "错题", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody QtMistake qtMistake)
    {
        return toAjax(qtMistakeService.updateQtMistake(qtMistake));
    }

    /**
     * 删除错题
     */
    @PreAuthorize("@ss.hasPermi('qt:mistake:remove')")
    @Log(title = "错题", businessType = BusinessType.DELETE)
	@DeleteMapping("/{mistakeIds}")
    public AjaxResult remove(@PathVariable String[] mistakeIds)
    {
        return toAjax(qtMistakeService.deleteQtMistakeByMistakeIds(mistakeIds));
    }
}
